package mspdt.ubzuuch.mn;

import java.util.ArrayList;
import android.app.Activity;
import android.graphics.Color;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListAdapterOfDB extends ArrayAdapter<Integer> {
	private final Activity context;
	private final ArrayList<String> names;
	private final ArrayList<String> desc;
	private final ArrayList<String> prices;
	private final ArrayList<String> images;
	private final ArrayList<String> categories;
	private final ArrayList<Integer> ids;
	private  ImageLoader imageLoader; 
	
	public ListAdapterOfDB(Activity context, ArrayList<String> names, ArrayList<String> desc, ArrayList<String> prices, ArrayList<String> images, ArrayList<String> categories, ArrayList<Integer> ids) {
		super(context, R.layout.list_body, ids);
		this.context = context;
		this.names = names;
		this.desc = desc;
		this.prices=prices;
		this.images=images;
		this.categories=categories;
		this.ids=ids;
		imageLoader=new ImageLoader(context.getApplicationContext());
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if(convertView==null)
		{
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.list_body, null);
		}
		if(categories.get(position).equals("1"))
			convertView.setBackgroundColor(Color.WHITE);
		else if(categories.get(position).equals("2"))
			convertView.setBackgroundColor(Color.parseColor("#FFFFCC"));
		else if(categories.get(position).equals("3"))
			convertView.setBackgroundColor(Color.parseColor("#CCCCFF"));
		TextView tv_name = (TextView)convertView.findViewById(R.id.list_name);
		TextView tv_desc = (TextView)convertView.findViewById(R.id.list_desc);
		TextView tv_price = (TextView)convertView.findViewById(R.id.list_price);
		ImageView image = (ImageView)convertView.findViewById(R.id.list_image);
		tv_name.setText(Html.fromHtml(names.get(position)));
		tv_desc.setText(Html.fromHtml(desc.get(position)));
		tv_price.setText(Html.fromHtml(prices.get(position)));
		imageLoader.DisplayImage(context.getResources().getString(R.string.url_room_image)+images.get(position).split(",")[0], image);
		return convertView;
	}
//	@Override
//	public void notifyDataSetChanged() {
//	    super.notifyDataSetChanged();  
//	}
}